import { instance } from "@/request"

class EventHttp {
  static BASE_URL = "http://localhost:3000/back"
  static getHttp({ url }) {
    return new Promise((resolve, reject) => {
      instance.get(this.BASE_URL + url).then((res) => {
        resolve(res)
      })
    })
  }
  static putHttp({ url }) {
    return new Promise((resolve, reject) => {
      instance.put(this.BASE_URL + url).then((res) => {
        resolve(res)
      })
    })
  }
  static postHttp({ url, param }) {
    return new Promise((resolve, reject) => {
      instance.post(this.BASE_URL + url, param).then((res) => {
        resolve(res)
      })
    })
  }
  /* 
    分页请求所有没处理过的数据
    这个要传参数:page,size
   */
  static getPageEvent(page, size) {
    let mypage = page.value
    //console.log(mypage);
    //console.log(`/getallevent?page=${mypage}&size=${size}`);
    return this.getHttp({
      url: `/getallevent?page=${mypage}&size=${size}`,
    })
  }
  /* 请求得到饼状图的数据 */
  static getPieData() {
    return this.getHttp({
      url: `/eventpie`,
    })
  }
  /* 请求得到折线图的数据 */
  static getLineData() {
    return this.getHttp({
      url: `/eventline`,
    })
  }
  /* 通过事件 */
  static passEvent(id) {
    return this.putHttp({
      url: `/passevent/${id}`,
    })
  }
  /* 通过事件 */
  static ignoreEvent(id) {
    return this.putHttp({
      url: `/ignoreevent/${id}`,
    })
  }
  /* 上报事件 */
  static submitEvent = (param) => {
    return this.postHttp({
      url: "/event",
      param: param,
    })
  }
}
export { EventHttp }
